package com.dxy.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                  HttpServletResponse httpServletResponse, Object o, Exception e) {
        MyException myException=null;
        if(e instanceof MyException){
            myException=(MyException)e;
        }else{
            myException=new MyException("服务超时");
        }
        ModelAndView mv=new ModelAndView();
        mv.addObject("msg",myException.getMessge());
        mv.addObject("msg2",mv.toString());
        mv.setViewName("error");
        return mv;
    }
}
